﻿using System;
using System.Collections.Generic;
using System.Net.Http;
using WJ.DataSender.Service.Models;
using WJ.DataSender.Service.Models.ResultModel;
using Newtonsoft;
using Newtonsoft.Json;
using NLogManager;
using System.Threading.Tasks;
using WJ.DataSender.Service.Commen;
using WJ.DataSender.Service.Models.ConfigModel;
using System.Linq;
using System.Text;
using WJ.DataSender.Service.Implement;
using WJ.DataSender.Service.Models.RequestModel;

namespace WJ.DataSender.Service
{
    /// <summary>
    /// WJ平台的处理引擎
    /// </summary>
    public class WjByAllEquipMessageHandle : BaseMessageHandle<WjByAllEquipRequestModel, WjByResultModel>
    {
        private readonly PlatformInfo platform = CacheValues.AppsettingConfig.Platforms.Where(p => p.PlatformName == PlatformType.WJ_BY.ToString()).FirstOrDefault();

        public WjByAllEquipMessageHandle(IHttpClientFactory httpClientFactory) : base(httpClientFactory)
        {
            //获取对应平台接口对接信息
            PlatformUrl = platform.PlatformDomain + platform.ApiList[3].Route;
            PlatformName = platform.PlatformName;
            StopSend = platform.ApiList[3].StopSend;
        }

        /// <summary>
        /// 重写处理请求内容的方法
        /// </summary>
        /// <param name="method"></param>
        /// <param name="url"></param>
        /// <param name="message"></param>
        /// <returns></returns>
        public override HttpRequestMessage HandleRequest(HttpMethod method, string url, WjByAllEquipRequestModel message)
        {
            var request = new HttpRequestMessage(method, url);
            request.Headers.Add("Accept", "application/vnd.github.v3+json");
            request.Headers.Add("User-Agent", "HttpClientFactory-Sample");
            if (message != null)
            {
                request.Content = new StringContent(JsonConvert.SerializeObject(message), Encoding.UTF8);
            }
            return request;
        }
    }
}
